package com.servlet.user;

import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/judgeLoginServlet")
public class JudgeLoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        Object user = session.getAttribute("user");
        if(user != null) {
            ObjectMapper mapper = new ObjectMapper();
            String userStr = mapper.writeValueAsString(user);
            response.getWriter().write("{\"status\":\"0\",\"message\":\"ok\",\"data\":"+userStr+"}");
        }else {
            response.getWriter().write("{\"status\":\"1\",\"message\":\"no\",\"data\":\"\"}");
        }

    }
}
